// ==UserScript==
// @name         tieba_filter
// @namespace    http://your.homepage/
// @version      0.8.137
// @description  贴吧过滤
// @author       @背叛丿拂晓
// @match        http://tieba.baidu.com/f?kw=*
// @icon         https://git.oschina.net/wscl123/user-scripts/raw/master/bluerain.png
// ==/UserScript==
var posts;
var re = /求助|为什么|为啥|怎么破|求破|救命|请问|吗|问题|啥原因|啥回事|安装不了|怎么办/; //匹配正则
$(function () {
    //加载网页时执行删除
    startRemove(re, 500);
    //请求下一页[指定页]时执行
    $(document).ajaxSuccess(function (event, xhr, settings) {
        if (settings.url.indexOf('f?kw=') != -1) { //判断为翻页完成
            //立马执行删除
            startRemove(re, 500);
        }
    });
});

function Post(title, abs, $title) { //Post[帖子类型]
    this.title = title; //标题内容
    this.abs = abs; //摘要内容
    this.$title = $title; //标题JQ对象
    if (typeof this.remove != 'function') {
        Post.prototype.remove = function () {
            this.$title.parents('li').remove(); //移除方法
            console.info(this.title+':已删除');
        }
    }
}
//[开始删除]函数
function startRemove(re, ms) {
    setTimeout(function () {
        posts = getPosts();
        //遍历帖子对象数组
        for (var i = 0; i < posts.length; i++) {
            var curPost = posts[i];
            //判断是否删除
            if (curPost.title.search(re) != -1) {
                curPost.remove();
            }
        }
        posts = null;
    }, ms);
}
//获取全部帖子对象函数
function getPosts() {
    var posts = [];
    $('.threadlist_text.threadlist_title.j_th_tit').each(function (i, e) {
        var $this = $(e);
        var $title = $this.find('a');
        var title = $title.text();
        posts.push(new Post(title, null, $this)); //写入所有帖子对象到数组中
    });
    return posts;
}
